package de.msspp.btservice;


import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Dialog extends Activity {
	
	private static final int RESULT_CONNECT=4;
	private static final int RESULT_DISCONNECT=5;
	
	Button send;
	Button connect;
	Button disconnect;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Setup the window
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.dialog);
        
        send = (Button)findViewById(R.id.send_message);
        connect = (Button)findViewById(R.id.connect);
        disconnect = (Button)findViewById(R.id.disconnect);
        
        OnClickListener listener = new OnClickListener() {
        	public void onClick(View v){
        		Intent intent = new Intent();
        		if(v.equals(send)){
        			 String message = "Hallo, Test.......";
                     sendMessage(message);
        		}
        		else if(v.equals(connect)){
        			BluetoothDevice selectedDevice= (BluetoothDevice) getIntent().getExtras().get("device");
            		intent.putExtra("device", selectedDevice);
            		
            	     // Set result and finish this Activity
            		setResult(RESULT_CONNECT, intent);
            		finish();
        		}
        		else if(v.equals(disconnect)){
        			setResult(RESULT_DISCONNECT);
        			finish();
        			
        		}
        	}
        };
        
        connect.setOnClickListener(listener);
        disconnect.setOnClickListener(listener);
        send.setOnClickListener(listener);		
        
     // Set result CANCELED incase the user backs out
        setResult(Activity.RESULT_CANCELED);
	}
	
	private void sendMessage(String msg){
		Intent intent = new Intent();
        intent.putExtra("message", msg);
        
     // Set result and finish this Activity
        setResult(Activity.RESULT_OK, intent);
        finish();
	}
}
